home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Science⁄Math / VideoToolbox / Utilities / GrabDrivers / GrabSlotDrivers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-11  |  3.8 KB  |  120 lines  |  [TEXT/KAHL]

  1. /* GrabSlotDrivers.c
  2. Repeatedly calls the Slot Manager to get every slot driver and puts each in its
  3. own file. These files can then be perused with the ResEdit CODE viewer. 
  4.  
  5. The ResEdit CODE viewer is a public domain file, for use with ResEdit, distributed by:
  6. Ira L. Ruben
  7. Apple Computer, Inc.
  8. 20525 Mariani Ave., MS: 37-A
  9. Cupertino, Ca. 95014
  10. Ira@Apple.Com
  11.  
  12. Note that GrabSlotDrivers gets the driver directly from the card's configuration
  13. ROM, whereas it is possible that your run-time System is actually superceding
  14. that by a later version of the driver loaded from the System file or by an INIT.
  15. If you want the active version of the driver it would be best to get it from the
  16. device manager, which is what GrabVideoDrivers.c does, though it skips non-video
  17. devices.
  18.  
  19. HISTORY:
  20. 2/89 dgp Wrote it as "video hacker II" using THINK C 3.
  21. 1/3/93 dgp updated it to THINK C 5 and renamed it GrabSlotDrivers.c
  22. 5/11/93    dgp    added check for Slot Manager, in response to bug report by Jonathan Brecher.
  23. */
  24. #include "VideoToolbox.h"
  25. #include <Errors.h>
  26. #include <Resources.h>
  27. #include <Traps.h>
  28. typedef struct {
  29.     short flags;
  30.     short blanks[3];
  31.     short open;
  32.     short prime;
  33.     short control;
  34.     short status;
  35.     short close;
  36.     Str255 name;
  37. } VideoDriver;
  38. void AddResourceToFile(unsigned char *filename,unsigned char *name,ResType type,int id,Handle handle);
  39. void GrabSlotDrivers(void);
  40.  
  41. void main(void)
  42. {
  43.     Require(0);
  44.     if(!TrapAvailable(_SlotManager))
  45.         PrintfExit("Sorry, no Slot Manager.\n");
  46.     MaximizeConsoleHeight();
  47.     printf("Welcome to GrabSlotDrivers.\n"
  48.     "This programs copies all drivers from your slot devices.\n"
  49.     "Note that this gets the driver from the card's configuration ROM, whereas\n"
  50.     "it is possible that your run-time System replaces\n"
  51.     "that by a later version of the driver loaded from the System file or INIT.\n");
  52.     GrabSlotDrivers();
  53. }
  54.  
  55. void GrabSlotDrivers(void)
  56. {
  57.     SpBlock mySpBlock;
  58.     SEBlock mySEBlock;
  59.     unsigned char name[256],filename[32];
  60.     OSErr error;
  61.     Ptr *handle;
  62.     int i;
  63.     int version;
  64.     VideoDriver *videoDriverPtr;
  65.     unsigned char *bytePtr;
  66.  
  67.     mySpBlock.spsExecPBlk = (Ptr) &mySEBlock;
  68.     mySpBlock.spSlot = 0;
  69.     mySpBlock.spID = 0;
  70.     mySpBlock.spExtDev = 0;
  71.  
  72.     while(1){
  73.         error = SNextSRsrc(&mySpBlock);
  74.         if(error==smNoMoresRsrcs) break;
  75.         if(error){
  76.             printf("SNextSRsrc error %d\n",error);
  77.             break;
  78.         }
  79.         mySpBlock.spResult = (unsigned long) &name;
  80.         error = SReadDrvrName(&mySpBlock);
  81.         printf("SReadDrvrName=%#s\n",name);    
  82.         printf("spSlot=%d,spID=%d,spExtDev=%d"
  83.             ,mySpBlock.spSlot,mySpBlock.spID,mySpBlock.spExtDev);
  84.         printf(",spCategory=%d,spCType=%d,spDrvrSW=%d,spDrvrHW=%d,spRefNum=%d\n"
  85.             ,mySpBlock.spCategory,mySpBlock.spCType,mySpBlock.spDrvrSW
  86.             ,mySpBlock.spDrvrHW,mySpBlock.spRefNum);
  87.  
  88.         /* filename must be truncated to 31 characters */
  89.         for (i=0;i<32;i++) filename[i]=name[i];
  90.         if((unsigned char)filename[0] > 31) filename[0]=31;
  91.         // Replace leading "." by "-" since the Mac filing system 
  92.         // is confused by filenames beginning with ".".
  93.         if(filename[1]=='.')filename[1]='-';
  94.         
  95.         /* get handle to desired driver resource */
  96.         error = SGetDriver(&mySpBlock);
  97.         if(!error) {
  98.             handle = (Ptr *) mySpBlock.spResult;
  99.     
  100.             // Is this a video driver?
  101.             videoDriverPtr=*(VideoDriver **)handle;
  102.             if(EqualString(name,videoDriverPtr->name,1,1)){
  103.                 // Probably is a video driver. The version number of a video driver 
  104.                 // is the first word-aligned word after the name string.
  105.                 bytePtr= videoDriverPtr->name;
  106.                 bytePtr += 1+bytePtr[0];    /* go to end of Pascal string */
  107.                 bytePtr = (unsigned char *)((long)(bytePtr+1) & ~1);    // round up to word boundary
  108.                 version = *(short *)bytePtr;
  109.             } else version=rand();
  110.         
  111.             AddResourceToFile(filename,name,'DRVR',version,handle);
  112.             printf("Driver copied to “%#s” file, using %d as id.\n",filename,version);
  113.             DisposHandle(handle);
  114.         }
  115.         else printf("No driver.\n");
  116.         printf("\n");
  117.     }
  118. }
  119.  
  120.